package org.zoomdev.zoom.web.parameter.pre.impl;

import org.zoomdev.zoom.web.action.ActionContext;
import org.zoomdev.zoom.web.parameter.PreParameter;
import org.zoomdev.zoom.web.parameter.PreParameterParser;
import org.zoomdev.zoom.web.utils.MediaType;


public final class JsonPreParamParser implements PreParameterParser {

    @Override
    public PreParameter preParse(ActionContext context) throws Exception {
        String contentType = context.getContentType();
        if (!MediaType.JSON.is(contentType)) {
            return null;
        }

        return new MapPreParameter(com.alibaba.fastjson2.JSON.parseObject(context.getRequest().getInputStream()));
    }

}